﻿using System;
using EzDesk.Core.Model;
using EzDesk.DesktopClient.Event;
using EzDesk.DesktopClient.FunctionWindowModule.ViewContract;
using EzDesk.DesktopClient.FunctionWindowModule.ViewModel;
using EzDesk.DesktopClient.ServiceLocator.CoreClientService;
using EzDesk.Utility.Net;
using Moq;
using NUnit.Framework;

namespace EzDesk.DesktopClient.UnitTest.FunctionWindowModule_Fixture
{
    [TestFixture]
    public class UpdateDataManagement_Fixture
    {
        [Test]
        public void update_function_test()
        {
            var feedModel = new Model.Feed
                                {
                                    FeedID = Guid.NewGuid().ToString(),
                                    IsAvailable = true,
                                    IsRead = true,
                                    IsMark = false
                                };

            var userProfile = new UserProfile { Id = Guid.NewGuid() };

            var m_CoreClientService = new Mock<ICoreClientService>();

            var m_UserManagement = new Mock<IUserManagement>();
            m_UserManagement.SetupGet(um => um.LogUser).Returns(userProfile);

            //Action
            var updateDataManagement = new UpdateDataManagement(m_CoreClientService.Object
                , m_UserManagement.Object);
            updateDataManagement.UpdateFeedStatusFromClientToServer();
            //Assert
            m_CoreClientService
                .Verify(service => service.UpdateFeedStatus(It.IsAny<FeedStatus[]>(), It.IsAny<string>()), Times.Never());

            //Action
            FeedStatusChangeEvent.Instance.Publish(feedModel);
            updateDataManagement.UpdateFeedStatusFromClientToServer();

            //Assert
            m_CoreClientService
                .Verify(service =>
                    service
                    .UpdateFeedStatus(It.Is<FeedStatus[]>(input
                        =>
                            (input[0].IsAvailable == feedModel.IsAvailable.Value)
                            && (input[0].IsMark == feedModel.IsMark.Value)
                            && (input[0].IsRead == feedModel.IsRead.Value)
                        )
                        , userProfile.Id.ToString()));
        }
    }
}
